var app = new Vue({
    el: '#app',
    data: {
        consignees: "",
        areaShow: false, //区域选择区块的显示和隐藏
        areas: [], //区域数据模板
        /*区域tab*/
        tabArea1: "",
        tabArea2: "请选择",
        tabArea3: "请选择",
        tabArea4: "请选择",
        /*区域tab的显示和隐藏*/
        areaTab1: true,
        areaTab2: false,
        areaTab3: false,
        areaTab4: false,
        /*点击区域tab时需要的parentCode*/
        parentCode2: "",
        parentCode3: "",
        /*点击区域tab时需要显示的areaName*/
        goName2: "",
        goName3: "",
        /*tab样式控制*/
        isCurr1: true,
        isCurr2: false,
        isCurr3: false,
        isCurr4: false,
        /*收获区域名称，省市乡镇分开*/
        provinceName: "请选择收货区域",
        cityName: "",
        countyName: "",
        villageName: "",
        /*获取选择的区域*/
        provinceId: window.historyPrivinceId,
        cityId: window.historyCityId,
        countyId: window.historyCountyId,
        villageId: window.historyVillageId,
        selectName:"北京"
    },
    mounted: function () {
        this.province(this.selectName);
    },
    methods: {
        initAddress(){
            this.isCurr1 = true;
            this.isCurr2 = false;
            this.isCurr3 = false;
            this.isCurr4 = false;
            this.provinceName = "请选择收货区域";
            this.cityName = "";
            this.countyName = "";
            this.villageName = "";
            this.tabArea1 = "";
            this.tabArea2 = "请选择";
            this.tabArea3 = "请选择";
            this.tabArea4 = "请选择";
            this.areaTab1 = true;
            this.areaTab2 = false;
            this.areaTab3 = false;
            this.areaTab4 = false;
        },
        /*关闭选择框*/
        closeArea(){
            document.getElementById("provinceName").innerHTML = window.historyProvinceName;
            document.getElementById("cityName").innerHTML = window.historyCityName;
            document.getElementById("countyName").innerHTML = window.historyDistrictName;
            document.getElementById("villageName").innerHTML = window.historyStreetName;
            this.initAddress();
            this.province(this.selectName);
            this.areaShow = false;
            var vueBox = document.getElementById("vueBox");
            vueBox.style.display = "block";
            var notVueBox = document.getElementById("notVueBox");
            notVueBox.style.display = "none";
            window.updataGoodsList(window.historyPrivinceId);
        },
        /*点击弹出区域选择框*/
        isAreaShow() {
            this.areaShow = !this.areaShow;
             if(this.areaShow == false){
                 document.getElementById("provinceName").innerHTML = window.historyProvinceName;
                 document.getElementById("cityName").innerHTML = window.historyCityName;
                 document.getElementById("countyName").innerHTML = window.historyDistrictName;
                 document.getElementById("villageName").innerHTML = window.historyStreetName;
                 var vueBox = document.getElementById("vueBox");
                 vueBox.style.display = "block";
                 var notVueBox = document.getElementById("notVueBox");
                 notVueBox.style.display = "none";
                 this.initAddress();
                 this.province(this.selectName);
                window.updataGoodsList(window.historyPrivinceId);
             }else {
                 var vueBox = document.getElementById("vueBox");
                 vueBox.style.display = "block";
                 var notVueBox = document.getElementById("notVueBox");
                 notVueBox.style.display = "none";
             }
            let that = this;
            document.addEventListener('click',function(e){
                if(e.target.parentNode.className!="list clearfix" && e.target.parentNode.className!="tab clearfix" && e.target.parentNode.className !="area_list" && e.target.parentNode.className != "divHide" && e.target.parentNode.className != "inp_area_box"){
                    if(that.areaShow != false){
                        document.getElementById("provinceName").innerHTML = window.historyProvinceName;
                        document.getElementById("cityName").innerHTML = window.historyCityName;
                        document.getElementById("countyName").innerHTML = window.historyDistrictName;
                        document.getElementById("villageName").innerHTML = window.historyStreetName;
                        var vueBox = document.getElementById("vueBox");
                        vueBox.style.display = "block";
                        var notVueBox = document.getElementById("notVueBox");
                        notVueBox.style.display = "none";
                        that.initAddress();
                        that.province(that.selectName);
                        that.areaShow = false;
                       /* window.updataGoodsList(window.historyPrivinceId);*/
                    }
                }
            });
        },
        /*加载获取省份*/
        province(areaName) {
            let that = this;
            $.ajax({
                type: "POST",
                //url:'https://'+ window.location.host +'/api/admin/amembership/adminGetRegionAddress.jhtml',
                //http://192.168.0.32:7204/abaseservice/area/getWarehouseCoverAddress
                url: root.replaceInter.replace_adminGetRegionAddress,
                cache: false,  //禁用缓存
                dataType: "json",
                data: {
                    range: '10',
                    level: '101'
                },  //传入组装的参数
                success: function (response) {
                    if (response.errorCode == 1) {
                        that.tabArea1 = areaName;
                        that.areas = response.list;
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    // alert(XMLHttpRequest);
                }
            });
        },
        /*点击选择区域（省市县乡）*/
        getArea(level, parentCode, areaName, isTab, addressId) {
            var nextlevel;
            let that = this;
            /*判断是否tab点击*/
            if (isTab == "tab") {
                var nextlevel = String(level);
                if (level == "101") {
                    that.cityName = "";
                    that.countyName = "";
                    that.villageName = "";
                } else if (level == "102") {
                    that.countyName = "";
                    that.villageName = "";
                } else if (level == "103") {
                    that.villageName = "";
                }
            } else if (isTab == "noTab") {
                if (level == '101') {
                    that.provinceName = areaName;
                    that.provinceId = addressId;
                    that.cityName = "";
                    that.countyName = "";
                    that.villageName = "";
                    that.cityId = '';
                    that.countyId = '';
                    that.villageId = '';
                }
                nextlevel = String(Number(level + 1));
            }
            if (nextlevel == "104") {
                //window.updataGoodsList(that.provinceId);
                that.villageName = areaName;
                that.villageId = addressId;
                that.tabArea4 = areaName;
                that.isCurr1 = false;
                that.isCurr2 = false;
                that.isCurr3 = false;
                that.isCurr4 = true;
                window.historyPrivinceId = that.provinceId;
                window.historyCityId = that.cityId;
                window.historyCountyId = that.districtId;
                window.historyVillageId = that.villageId;
                window.historyProvinceName = that.provinceName;   //历史省名称
                window.historyCityName = that.cityName;   //历史市名称
                window.historyDistrictName = that.countyName;  //历史县名称
                window.historyStreetName = that.villageName;
                console.log(window.historyStreetName)
                that.areaShow = !that.areaShow;
            } else {
                $.ajax({
                    type: "POST",
                    url:'https://'+ window.location.host +'/api/admin/amembership/adminGetRegionAddress.jhtml',
                    // url: root.replaceInter.replace_adminGetRegionAddress,
                    cache: false,  //禁用缓存
                    dataType: "json",
                    data: {
                        level: nextlevel,
                        parentCode: parentCode,
                    },  //传入组装的参数
                    success: function (response) {
                        if (response.errorCode == 1) {
                            if (response.errorCode == 1) {
                                that.areas = response.list;
                                that.isCurr1 = true;
                                that.isCurr2 = false;
                                that.isCurr3 = false;
                                that.isCurr4 = false;
                                if (nextlevel == '102') {
                                    that.areaType = response.list.level;
                                    that.areaTab2 = true;
                                    if (isTab == "noTab") {
                                        if (that.areas.length <= 0) {
                                            that.areaShow = !that.areaShow;
                                            return false;
                                        } else {
                                            that.areaTab3 = false;
                                            that.areaTab4 = false;
                                            that.tabArea2 = "请选择";
                                        }

                                        // that.areaTab3 = false;
                                        // that.areaTab4 = false;
                                        // that.tabArea2 = "请选择";

                                    }
                                    that.isCurr1 = false;
                                    that.isCurr2 = true;
                                    that.isCurr3 = false;
                                    that.isCurr4 = false;
                                    that.tabArea1 = areaName;
                                    that.parentCode2 = parentCode;
                                    that.goName2 = areaName;
                                } else if (nextlevel == '103') {
                                    that.areaType = response.list.level;
                                    that.areaTab3 = true;
                                    if (isTab == "noTab") {
                                        that.cityName = areaName;
                                        that.cityId = addressId;
                                        if (that.areas.length <= 0) {
                                            that.areaShow = !that.areaShow;
                                            return false;
                                        } else {
                                            that.areaTab4 = false;
                                            that.tabArea3 = "请选择";
                                        }
                                        that.areaTab4 = false;
                                        // that.tabArea3 = "请选择";
                                    }
                                    that.isCurr1 = false;
                                    that.isCurr2 = false;
                                    that.isCurr3 = true;
                                    that.isCurr4 = false;
                                    that.tabArea2 = areaName;
                                    that.parentCode3 = parentCode;
                                    that.goName3 = areaName;
                                } else if (nextlevel == '104') {
                                    that.areaType = response.list.level;
                                    that.tabArea3 = areaName;
                                    that.isCurr1 = false;
                                    that.isCurr2 = false;
                                    that.isCurr3 = true;
                                    that.isCurr4 = false;
                                    if (isTab == "noTab") {
                                        that.countyName = areaName;
                                        that.countyId = addressId;
                                        if (that.areas.length <= 0) {
                                            window.historyPrivinceId = that.provinceId;
                                            window.historyCityId = that.cityId;
                                            window.historyCountyId = that.countyId;
                                            window.historyProvinceName = that.provinceName;   //历史省名称
                                            window.historyCityName = that.cityName;   //历史市名称
                                            window.historyDistrictName = that.countyName;  //历史县名称
                                            window.historyStreetName = that.villageName;
                                            window.updataGoodsList(that.provinceId)
                                            that.areaShow = !that.areaShow;
                                            return false;
                                        } else {
                                            that.areaTab4 = true;
                                            that.tabArea4 = "请选择";
                                        }

                                        //that.tabArea4 = "请选择";
                                    }
                                }
                            }
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest);
                    }
                });
            }
        },
    },
});